home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2010 Summer - Disc 1 / WN_Ete2010_CD1.iso / Onglet5 / Weezo / Weezo setup.exe / {code_appDir} / www / local / genRSAKey.php < prev    next >
PHP Script  |  2010-05-19  |  2KB  |  56 lines

  1. <?php
  2. /**
  3.  * RSA Key generation
  4.  * Generates RSA key used for javascript password encryption
  5.  *
  6.  *
  7.  * PHP version 5
  8.  *
  9.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  10.  * that is available through the world-wide-web at the following URI:
  11.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  12.  * the PHP License and are unable to obtain it through the web, please
  13.  * send a note to license@php.net so we can mail you a copy immediately.
  14.  *
  15.  * @category   NA
  16.  * @package    NA
  17.  * @author     Nicolas Bruley / Peer 2 World <contact@weezo.net>
  18.  * @copyright  2005-2009 Nicolas Bruley / Peer 2 World
  19.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  20.  * @version    CVS: $Id:$
  21.  * @link       http://www.weezo.net
  22.  * @since      File available since Release 1.0.0
  23.  */
  24.  
  25.  
  26. echo ">";
  27. require_once 'Crypt/RSA.php';
  28. require_once 'Crypt/RSA/Math/BCMath.php';
  29.  
  30. define('MATH_LIBRARY', 'BCMath');
  31. $bcm= new Crypt_RSA_Math_BCMath;
  32.  
  33. $baseDir=str_replace('\\','/',dirname($_SERVER['SCRIPT_FILENAME']).'/../../');
  34.  
  35. if(file_exists($baseDir.'data/general.ini')) $config=parse_ini_file($baseDir.'data/general.ini');
  36.  
  37. if(isset($config['loginKeyLength'])) $keyLength=$config['loginKeyLength']; else $keyLength=384;
  38. // Generate key
  39. $key_pair = new Crypt_RSA_KeyPair($keyLength, MATH_LIBRARY, 'check_error',65537);
  40. $public_key = $key_pair->getPublicKey();
  41. $private_key = $key_pair->getPrivateKey();
  42. $key_length = $key_pair->getKeyLength();
  43.  
  44. // Save to file
  45. if(!$handle=fopen($baseDir.'data/RSAKey.cnf','w')) exit;
  46.  
  47. // key length
  48. fwrite($handle,'keyLength='.$keyLength."\n");
  49. // modulo
  50. fwrite($handle,'modulo='.$bcm->bin2int($public_key->getModulus())."\n");
  51. // Public exponent
  52. fwrite($handle,'publicExponent='.$bcm->bin2int($public_key->getExponent())."\n");
  53. // Private exponent
  54. fwrite($handle, 'privateExponent='.$bcm->bin2int($private_key->getExponent())."\n");
  55. fclose($handle);
  56. ?>